package com.kat.bookstore.web;

import java.sql.Connection;

public class ConnectionContext {
	
	private ConnectionContext(){}
	
	private static ConnectionContext instance = new ConnectionContext();
	
	public static ConnectionContext getInstance(){
		return instance;
	}
	
	private ThreadLocal<Connection> connectionThreadLocal =
			new ThreadLocal<>();
	
	//绑定
	public void bind(Connection connection){
		connectionThreadLocal.set(connection);
	}
	
	//获取
	public Connection get()	{
		return connectionThreadLocal.get();
	}
	
	//解绑
	public void remove(){
		connectionThreadLocal.remove();
	}

}
